﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Cricket.LinqModel;

using System.Configuration;

namespace Cricket.LinqData
{
    public class CricketDatabaseFactory
    {
        private static string _databaseName = String.Empty;
        private static string _datbaseServer = String.Empty;
        private static string _connectionString = string.Empty;
        private static string _userId = "sa";
        private static string _password = "jaydeep";

        public static string DatabaseName
        {
            get { return _databaseName; }
            set { _databaseName = value; }
        }

        public static string DatabaseServer
        {
            get { return _datbaseServer; }
            set { _datbaseServer = value; }
            // set { _databaseName = value; }
        }

        public static string ConnectionString
        {
            get
            {
                if (string.IsNullOrEmpty(_connectionString))
                {
                    if (ConfigurationManager.ConnectionStrings["conn"] != null)
                        _connectionString = ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
                    else
                        _connectionString = string.Format("Database={0};Server={1};Integrated Security=false; user id={2};password={3};",
                            _databaseName, _datbaseServer, _userId, _password);
                }
                return _connectionString;
            }
            set { _connectionString = value; }
        }

        public static string UserId
        {
            get { return _userId; }
            set { _userId = value; }
        }

        public static string Password
        {
            get { return _password; }
            set { _password = value; }
        }

        public static CricketDbContext CreateDbContext()
        {
            return new CricketDbContext(ConnectionString);
        }
    }
}
